//
//  XJRightCollectionSectionHeaderView.m
//  XinJiangMall
//
//  Created by RaoBo on 2018/5/10.
//  Copyright © 2018年 Tzyang. All rights reserved.
//

#import "XJRightCollectionSectionHeaderView.h"
// Model
#import "XJLeftTableModel.h"

@interface XJRightCollectionSectionHeaderView()
/**黄色的圆点 选中状态显示*/
@property(nonatomic, strong) UIView *yellowDotView;
/**name Lb*/
@property(nonatomic, strong) UILabel *nameLb;

@end
@implementation XJRightCollectionSectionHeaderView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.yellowDotView = [UIView new];
    // 默认是隐藏的。滚动之后才显示。咋做？ 暂时实现不了。
//    self.yellowDotView.hidden = YES;
    
//    self.yellowDotView.backgroundColor = XJCOLOR_RGB(255, 218, 67);
    self.yellowDotView.backgroundColor = XJCOLOR_RGB(240, 240, 240);

    self.yellowDotView.layer.masksToBounds = YES;
    self.yellowDotView.layer.cornerRadius = self.yellowDotView.frame.size.width / 2;
    [self addSubview:self.yellowDotView];

    self.nameLb = [UILabel new];
//    self.nameLb.backgroundColor = [UIColor redColor];
    [self addSubview:self.nameLb];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    // 目标:水平居中一左一右
    CGFloat s_h = self.frame.size.height;
    CGFloat label_h = 20;
    
    self.yellowDotView.frame = CGRectMake(10, (s_h - label_h)/2, label_h*0.7, label_h*0.7);
    self.yellowDotView.layer.masksToBounds = YES;
    self.yellowDotView.layer.cornerRadius = self.yellowDotView.frame.size.height / 2;

    self.nameLb.frame = CGRectMake(40, (s_h - label_h)/2, 150, label_h);
    
    
    // 用不了啊
//    self.yellowDotView.sd_layout.leftSpaceToView(self, 10)
//    .topSpaceToView(self, 10)
//    .heightIs(20)
//    .widthIs(20);
    
//    self.nameLb.sd_layout.leftSpaceToView(self.yellowDotView, 10)
//    .centerXEqualToView(self)
//    .heightIs(150)
//    .heightIs(20);
}

- (void)setModel:(XJLeftTableModel *)model {
    _model = model;
    
    self.nameLb.text = model.name;
    
    if (model.isChecked) {
        self.yellowDotView.backgroundColor = XJCOLOR_RGB(255, 218, 67);
    }else {
        self.yellowDotView.backgroundColor = XJCOLOR_RGB(240, 240, 240);
    }
}
@end
